<template>
  <div class="aside-control">
    <div class="control-list">
      <a-button
        class="control-item"
        v-for="(item, index) in tabList"
        :key="index"
        :disabled="checkItemDisabled(item)"
      >
        <a-tooltip placement="right">
          <template slot="title">
            <span>{{ item.hover }}</span>
          </template>
          <div class="item-body" @click.stop="handleItem(item)">
            <i
              class="iconfont"
              :class="[item.icon, item.disabled ? 'disabled' : '']"
            ></i>
          </div>
        </a-tooltip>
      </a-button>
    </div>
  </div>
</template>

<script>
export default {
  name: "",
  props: {},
  data() {
    return {
      tabList: [
        {
          icon: "icon-mokuai-tuiyibu",
          type: "cancel",
          hover: "撤销",
          disabled: false,
        },
        {
          icon: "icon-mokuai-qianyibu",
          type: "forward",
          hover: "恢复",
          disabled: false,
        },
        {
          icon: "icon-mokuai-baocun",
          type: "save",
          hover: "保存",
          disabled: false,
        },
        {
          icon: "icon-mokuai-fengge",
          type: "theme",
          hover: "页面风格",
          disabled: false,
          controlComName: "themeControl",
          params: {
            color: "",
          },
        },
        {
          icon: "icon-mokuai-yemianshezhi",
          type: "pageSet",
          hover: "页面设置",
          disabled: false,
        },
      ],
    };
  },
  watch: {},
  computed: {
    currentStorePage() {
      return this.$diyObser.store.currentPage;
    },
    actionStep() {
      return this.$diyObser.store.actionStep;
    },
    returnAction() {
      return this.$diyObser.store.returnAction;
    },
  },
  created() {},
  methods: {
    handleItem(item) {
      if (item.disabled) return;
      if (item.type == "cancel") {
        // 撤销操作，只需关住store的actionStep即可；记录数组的操作，进行反操作即可
        this.$emit("handleAsideCancel");
      }
      if (item.type == "forward") {
        console.log("恢复操作");
      }
      if (item.type == "save") {
        this.$emit("handleAsideSave");
      }
      if (item.type == "theme") {
        console.log("主题配色");
        this.$emit("handleTheme", { item });
      }
      if (item.type == "pageSet") {
        console.log("编辑页面配置");
        if (this.currentStorePage.id) this.$emit("handlePageSet", { item });
      }
    },
    checkItemDisabled(item) {
      if (item.type == "cancel" && !this.actionStep.length) return true;
      if (item.type == "forward" && !this.returnAction.length) return true;
      return false;
    },
  },
};
</script>

<style lang="scss" scoped>
.aside-control {
  width: 40px;
  min-height: 200px;
  position: absolute;
  left: calc(50% + 226px);
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 111;
  .control-list {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    .control-item {
      width: 40px;
      height: 40px;
      display: flex;
      justify-content: center;
      align-items: center;
      margin-bottom: 10px;
      position: relative;
      border: 0 none;
      background-color: inherit;
      box-shadow: none;
      border-radius: 50%;
      .item-bg {
        width: 40px;
        height: 40px;
        background: #ffffff;
        border-radius: 50%;
        display: none;
      }
      .item-body {
        width: 100%;
        height: 100%;
        position: absolute;
        left: 0;
        top: 0;
        z-index: 11;
        display: flex;
        justify-content: center;
        align-items: center;
        border-radius: 50%;
        overflow: hidden;
        .iconfont {
          font-size: 24px;
        }
        .disabled {
          color: #838485;
        }
      }
    }

    .control-item :hover {
      background: #ffffff;
      border-radius: 50%;
      color: #1890fc;
    }
  }
}
</style>
